package com.ruoyi.web.controller.system;

import java.util.Date;
import java.util.List;

import com.ruoyi.framework.util.ShiroUtils;
import com.ruoyi.system.domain.CmsArticle;
import com.ruoyi.system.service.ICmsArticleService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.CmsComment;
import com.ruoyi.system.service.ICmsCommentService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 评论 信息操作处理
 * 
 * @author ruoyi
 * @date 2019-05-30
 */
@Controller
@RequestMapping("/system/cmsComment")
public class CmsCommentController extends BaseController
{
    private String prefix = "system/cmsComment";
	
	@Autowired
	private ICmsCommentService cmsCommentService;
	
	@RequiresPermissions("system:cmsComment:view")
	@GetMapping()
	public String cmsComment()
	{
	    return prefix + "/cmsComment";
	}
	
	/**
	 * 查询评论列表
	 */
	@RequiresPermissions("system:cmsComment:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(CmsComment cmsComment)
	{
		startPage();
        List<CmsComment> list = cmsCommentService.selectCmsCommentList(cmsComment);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出评论列表
	 */
	@RequiresPermissions("system:cmsComment:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CmsComment cmsComment)
    {
    	List<CmsComment> list = cmsCommentService.selectCmsCommentList(cmsComment);
        ExcelUtil<CmsComment> util = new ExcelUtil<CmsComment>(CmsComment.class);
        return util.exportExcel(list, "cmsComment");
    }
	
	/**
	 * 新增评论
	 */
	@GetMapping("/add")
	public String add(ModelMap modelMap)
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存评论
	 */
	@RequiresPermissions("system:cmsComment:add")
	@Log(title = "评论", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(CmsComment cmsComment)
	{
		cmsComment.setCreateBy(ShiroUtils.getLoginName());
		cmsComment.setCreateTime(new Date());
		return toAjax(cmsCommentService.insertCmsComment(cmsComment));
	}

	/**
	 * 修改评论
	 */
	@GetMapping("/edit/{commentId}")
	public String edit(@PathVariable("commentId") Long commentId, ModelMap mmap)
	{
		CmsComment cmsComment = cmsCommentService.selectCmsCommentById(commentId);
		mmap.put("cmsComment", cmsComment);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存评论
	 */
	@RequiresPermissions("system:cmsComment:edit")
	@Log(title = "评论", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(CmsComment cmsComment)
	{
		cmsComment.setUpdateBy(ShiroUtils.getLoginName());
		cmsComment.setUpdateTime(new Date());
		return toAjax(cmsCommentService.updateCmsComment(cmsComment));
	}
	
	/**
	 * 删除评论
	 */
	@RequiresPermissions("system:cmsComment:remove")
	@Log(title = "评论", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(cmsCommentService.deleteCmsCommentByIds(ids));
	}
	
}
